﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MN.Framework.Common
{
    [Serializable]
    public class RequiredValidationRule : ValidationRule
    {
        // Methods
        public override bool IsValid(BaseEntity record, string propertyName)
        {
            object obj2 = base.GetValue(record, propertyName);
            bool flag = true;
            if (obj2 == null)
            {
                flag = false;
            }
            else if (obj2.GetType() == typeof(string))
            {
                flag = ((string)obj2).Trim().Length > 0;
            }
            else if (obj2.GetType() == typeof(DateTime))
            {
                DateTime time = (DateTime)obj2;
                flag = ((time.Year != 1) || (time.Month != 1)) || (time.Day != 1);
            }
            if (!flag)
            {
                List<ColumnInfo> columns = new List<ColumnInfo>();
                record.GetColumns(columns);
                base.ErrorMessage = string.Format(FrameworkMessages.ValueCantBeEmpty.DefaultValue, columns.Find(c => c.Name == propertyName).HeaderText);
            }
            return flag;
        }
    }
}
